<!doctype html>
<?php include("include/session.php"); ?>
<html>
	<head>
		<title>movienight</title>
		<link rel="stylesheet" href="css/bootstrap.min.css">
		<link rel="stylesheet" href="css/movienight.css">
	</head>
	<body>
	
		<?php
			/**
			 * The user is already logged in, not allowed to register.
			 */
			if($session->logged_in){
			   echo "<h1>Registered</h1>";
			   echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
				   ."<a href=\"main.php\">Main</a>.</p>";
			}
			/**
			 * The user has submitted the registration form and the
			 * results have been processed.
			 */
			else if(isset($_SESSION['regsuccess'])){
			   /* Registration was successful */
			   if($_SESSION['regsuccess']){
				  echo "<h1>Registered!</h1>";
				  echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, your information has been added to the database, "
					  ."you may now <a href=\"main.php\">log in</a>.</p>";
			   }
			   /* Registration failed */
			   else{
				  echo "<h1>Registration Failed</h1>";
				  echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
					  ."could not be completed.<br>Please try again at a later time.</p>";
			   }
			   unset($_SESSION['regsuccess']);
			   unset($_SESSION['reguname']);
			}
			/**
			 * The user has not filled out the registration form yet.
			 * Below is the page with the sign-up form, the names
			 * of the input fields are important and should not
			 * be changed.
			 */
			else{
		?>
	
		<div style="height: 100px;"></div>
		<form class="form-horizontal" action="process.php" method="POST">
			<fieldset>
				<?php
					$fields = array("firstName", "lastName", "email", "pass", "passConf");
					$fieldn = array("First Name", "Last Name", "Email", "Password", "Confirm Password");
					$fieldt = array("text", "text", "text", "password", "password");
				?>
				
				<?php foreach($fields as $index=>$field): ?>
				
				<?php $error = ($form->error($field) != ""); ?>
				
				<div class="control-group <?php if ($error) echo "error"; ?>">
					<label class="control-label" for="<?php echo $field; ?>">
						<?php echo $fieldn[$index]; ?>
					</label>
					<div class="controls">
						<input value="<?php echo $form->value($field); ?>" type="<?php echo $fieldt[$index]; ?>" id="<?php echo $field; ?>" name="<?php echo $field; ?>">
						<?php if ($error) : ?>
							<span class="help-inline"><?php echo $form->error($field); ?></span>
						<?php endif; ?>
					</div>
				</div>
				
				<?php endforeach; ?>
				
				<div class="control-group">
					<label class="control-label" for="gender">Gender</label>
					<div class="controls">
						<select id="gender" name="gender">
							<option value="0">Female</option>
							<option value="1">Male</option>
						</select>
					</div>
				</div>
				
				<div class="form-actions">
					<button type="submit" class="btn btn-primary">Register</button>
					<button type="button" class="btn" ><a class="btnLinks" href="mn_main.php">Cancel</a></button>
				</div>
				
				<input type="hidden" name="subjoin" value="1">
			</fieldset>
		</form>
		
		<?php
		}
		?>

		<script src="js/jquery-1.7.2.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>